import axios from 'axios'

const api = axios.create({
    baseURL: '/api',
    withCredentials: true
})

export const register = (username, password) =>
    api.post('/register', { username, password })

export const login = (username, password) =>
    api.post('/login', { username, password })

export const logout = () =>
    api.post('/logout')

export const checkAuth = () =>
    api.get('/profile')

export const getProfile = () =>
    api.get('/profile')

export const toggleSpace = (enabled) =>
    api.put('/space/toggle', { enabled })

export const generateModel = (data) =>
    api.post('/models/generate', data)

export const uploadModel = (formData) =>
    api.post('/models/upload', formData, {
        headers: { 'Content-Type': 'multipart/form-data' }
    })

export const getMyModels = () =>
    api.get('/models')

export const updateModel = (id, data) =>
    api.put(`/models/${id}`, data)

export const deleteModel = (id) =>
    api.delete(`/models/${id}`)

export const addComment = (modelId, content, isVoice = false) =>
    api.post(`/models/${modelId}/comments`, { content, is_voice: isVoice })

export const getPublicSpace = (username) =>
    api.get(`/space/${username}`)

export const getModelFile = (id) =>
    `/api/model/${id}/file`

export default api
